#include "abc-server-tool-controller.h"

#include "util/logger/logger.h"
#include "util/net/http-request.h"
#include "util/net/http-response.h"
#include "util/config/preference-entry.h"


static const PreferenceEntry<std::string> prefToolKey("tool.key");

static const char *title = "AbcToolController ";


AbcToolController::AbcToolController()
{
}

void AbcToolController::handleHttpRequest(const HttpRequest &request, HttpResponse &response)
{
	// 如果 key 不对则丢弃
	if (*prefToolKey != request.paramValueOf("key")) {
		LOGD << title << "bad key";
		response.discard();
		return;
	}

	const std::string_view toolName = request.paramValueOf("tool-name");
	if (toolName == "ping") {
		response.buffer() = request.paramValueOf("ping-content");
		return;
	}

	// 如果没有对应的工具则丢弃
	LOGD << title << "bad tool name";
	response.discard();
	return;
}
